package com.hgd.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Session;

import com.hgd.DAO.WaringDAO;
import com.hgd.ORM.Waring;
import com.hgd.hibernate.HibernateUtil;

public class WaringImpl implements WaringDAO{

	public List<Waring> getWaringList() {
		Session session = HibernateUtil.getSesion();
		List<Waring> waringList = new ArrayList<Waring>();
		try {
			session.beginTransaction();		
			waringList = session.createQuery("from Waring").list();
			for (Iterator iterator = waringList.iterator(); iterator.hasNext();) {
				Waring waring = (Waring) iterator.next();
				System.out.println(waring.getValue());
			}
			session.flush();
			session.getTransaction().commit();
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}finally{
			HibernateUtil.closeSession(session);
		}
		return waringList;
	}
	public static void main(String[] args) {
		WaringDAO dao = new WaringImpl();
		dao.getWaringList();
	}
}
